package com.weiiew.backend.controller;

import com.weiiew.backend.exception.ExecutorParamsException;
import com.weiiew.backend.utils.ApiResponse;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.awt.*;
import java.io.IOException;
import java.nio.file.FileAlreadyExistsException;

/**
 * @Description 全局异常处理
 * @Author 魏锴
 * @Date 2025/4/29
 */
@RestControllerAdvice
public class GlobalAdviceController {
    @ExceptionHandler(IOException.class)
    public ApiResponse IOException(IOException e) {
        return ApiResponse.failure(e.getMessage());
    }

    @ExceptionHandler(FileAlreadyExistsException.class)
    public ApiResponse FileAlreadyExistsException(FileAlreadyExistsException e) {
        return ApiResponse.failure(e.getMessage());
    }

    @ExceptionHandler(ExecutorParamsException.class)
    public ApiResponse ExecutorParamsException(ExecutorParamsException e) {
        return ApiResponse.failure(e.getMessage());
    }

    @ExceptionHandler(AWTException.class)
    public ApiResponse AWTException(AWTException e) {
        return ApiResponse.failure("当前电脑不支持无头环境！");
    }

    @ExceptionHandler(IllegalStateException.class)
    public ApiResponse IllegalStateException(IllegalStateException e) {
        return ApiResponse.failure(e.getMessage());
    }
}
